<?php
class CommonModel extends Model {
	public function getPosition($id,$isChannel = 0){
		if($isChannel){
			$position = $id;
		}else{
			$Category = D('Category')->where('status = 1 AND id ='.$id)->find();
			if($Category){
				$Channel = D('Channel')->where('status = 1')->find($Category['channelid']);
			}else{
				$Channel = D('Channel')->where('status = 1 AND action = "'.MODULE_NAME.'"')->find();
			}
			
			$position = $Channel['id'];
		}
		return $position;
	}
	public function getClassPosition($id){
		$type = D('Category')->where('status=1')->find($id);
		if($type['pid']==0){
			$ClassPosition = array($id);
		}else{
			$ClassPosition = array($type['pid'] , $id);
		}
		return $ClassPosition;
	}
	public function getCategoryMap($id){
		$type = D('Category')->where('status=1')->find($id);
		$childid = D('Category')->where('status=1 AND pid='.$type['id'])->select();
		if($childid){
			$ary[] = $id;
			foreach($childid as $val) $ary[]=$val['id'];
			$map['cid']	= array('in',$ary);
		}else{
			$map['cid'] = array('eq',$id);
		}
		return $map;	
	}
	public function getRomCategoryMap($id){
		$type = D('Category')->where('status=1')->find($id);
		$childid = D('Category')->where('status=1 AND pid='.$type['id'])->select();
		if($childid){
			$ary[] = $id;
			foreach($childid as $val) $ary[]=$val['id'];
			$map['cid']	= array('in',$ary);
		}else{
			$map['cid'] = array('eq',$id);
		}
		return $map;
	}
	public function getChannelMap($id){
		$type = D('Category')->where('status = 1 AND channelid = '.$id)->select();
		if(is_array($type)){
			foreach($type as $val) $ary[]=$val['id'];
			$map['cid']	= array('in',$ary);
		}
		return $map;
	}
}